
function formSubmit(){
	if(checkEmpty()){
		return;
	}
	if(!checkword()){
		return;
	}
	
	$('#registerForm').submit();
}

function checkword(){
	if($('#password1').val() != $('#password2').val()){
		$('#password_group').addClass("control-group error");
		$('#confirmpassword_group').addClass("control-group error");
		return false;
	}else{
		$('#password_group').removeClass("control-group error");
		$('#confirmpassword_group').removeClass("control-group error");
		return true;
	}
}

function checkEmpty(){
	var isEmpty = false;
	if(trim($('#username').val()) == ''){
		$('#username_group').addClass("control-group error");
		isEmpty = true;
	}else{
		$('#username_group').remove("control-group error");
	}
	if(trim($('#password1').val()) == ''){
		$('#password_group').addClass("control-group error");
		isEmpty = true;
	}else{
		$('#password_group').remove("control-group error");
	}
	if(trim($('#password2').val()) == ''){
		$('#confirmpassword_group').addClass("control-group error");
		isEmpty = true;
	}else{
		$('#confirmpassword_group').remove("control-group error");
	}
	if(trim($('#email').val()) == ''){
		$('#email_group').addClass("control-group error");
		isEmpty = true;
	}else{
		$('#email_group').remove("control-group error");
	}
	
	return isEmpty;
}

function trim(str){ //remove left and right space
	 	 return str.replace(/(^\s*)|(\s*$)/g, "");
	 }
function ltrim(str){ //remove left space
	     return str.replace(/(^\s*)/g,"");
	 }
function rtrim(str){ //remove right space
	     return str.replace(/(\s*$)/g,"");
	 }